home *** CD-ROM | disk | FTP | other *** search
- PROGRAM TINTLOOK ; { by Steve Pauley 3/9/87 }
- { view TINY format pictures in any directory }
-
- CONST
- {$I GEMCONST.PAS}
- (* ... your CONSTants ... *)
-
- TYPE
- {$I gemtype.pas} { note that case doesn't matter }
- (* ... your TYPEs ... *)
- Pic_Dat = PACKED ARRAY [ 1..32034 ] of Byte;
- Screen = PACKED ARRAY [ 1..32000 ] of Byte;
- S_Ptr = ^Screen; { pointer to screen data }
- Path_Chars = PACKED ARRAY [ 1..80 ] OF Char ;
-
- VAR
- (* ... your VARiables ... *)
- Pic_Buf : Pic_Dat; { a place to read picture file data into }
- Scn_buf : Screen; { a place to stash the screen }
- Scn_ptr : S_Ptr; { a pointer to screen }
- Dat_Ptr : Integer ; { position of next pixil data in Pic_Buf array }
- Scn_Buf_Ptr : Integer ; { position of next pixil data in Scn_Buf array }
- Starting_Rez : Integer ; { resolution program was run from }
- Pic_Rez : Integer ; { store picture resolution value }
- Kolor_Reg : ARRAY[ 0..15 ] OF Integer; { stores color registers }
- Starting_Kolor_Reg: ARRAY[ 0..15 ] OF Integer; { stores color registers }
- X_Screen : Long_Integer ; { screen location return from xbios call }
- More : Boolean ; { if true show another picture }
- Valid_Name : Boolean; { flag for valid file name extender }
- F_Name, P_Name : Path_Name ; { file an path names for gem dialoge box }
-
- {$I gemsubs} { and that ".PAS" is default }
-
- FUNCTION Logical_Screen : Long_Integer;
- XBIOS($3);
-
- FUNCTION Screen_Rez : integer;
- XBIOS($4);
-
- PROCEDURE Set_Screen( Log_Scn, Phy_Scn : Long_Integer ; Rez : Integer );
- XBIOS($5);
-
- FUNCTION Set_Col( AI,BI : Integer ): Integer ; {read and set color reg.}
- XBIOS( 7 );
-
- PROCEDURE Save_Kolors; { saves color values into globle array Kolor_Reg }
- VAR I :Integer;
- BEGIN
- FOR I := 0 TO 15 DO Kolor_Reg[ I ] := Set_Col( I, -1 );
- END; { of Save_Kolors }
-
- PROCEDURE Restore_Kolors; { restores color values from globle array Kolor_Reg }
- VAR I, Junk :Integer;
- BEGIN
- FOR I := 0 TO 15 DO Junk := Set_Col( I, ( Kolor_Reg[ I ] ) );
- END; { of Restore_Kolors }
-
- PROCEDURE Make_Path( VAR ps : Path_Name ; VAR cs : Path_Chars ) ;
- VAR
- i : Integer ;
- BEGIN
- FOR i := 1 TO Length( ps ) DO
- BEGIN
- cs[i] := ps[i] ;
- END ;
- cs[ length(ps)+1 ] := Chr(0) ;
- END;
-
- { Open an existing file. }
- FUNCTION f_open( VAR name : Path_Chars ; mode : Integer ) : Integer ;
- GEMDOS( $3d ) ;
- { Mode - 0=read only, 1=write only, 2=reading and writing }
-
- { Close an open file. }
- FUNCTION f_close( handle : Integer ) : Integer ;
- GEMDOS( $3e ) ;
-
- { Read bytes from a file. }
- FUNCTION f_read( handle : Integer ; count : Long_Integer ; VAR buf : Pic_Dat
- ) : Long_Integer ;
- GEMDOS( $3f ) ;
-
- FUNCTION Physbase : S_Ptr; { xbios routine returns address of screen }
- Xbios( 2 );
-
- PROCEDURE Sav_scn; { proc saves screen to buf }
- {$P-} { turn pointer checking off }
- begin
- Scn_ptr := Physbase; { get addr of screen in memory }
- Scn_buf := Scn_Ptr^; { do assignment, copy entire array }
- end;
- {$P=} { restore pointer checking to old state }
-
- PROCEDURE Rest_scn; { restore screen from buf }
- {$P-} { turn pointer checking off }
- begin
- Scn_ptr := Physbase; { get addr of screen in memory }
- Scn_ptr^ := Scn_buf; { assign, copy array }
- end;
- {$P=} { set pointer checking to old state }
-
-
- PROCEDURE Ask_For_Name;
- VAR
- A1,A2,Alert : Str255 ;
- junk,IO_Error : Integer ;
- I : Integer; { temporary variable }
- Times : Integer; { compression counter }
- Stuff : FILE OF Integer;{ file type binder }
- P_New,P_Mark : Integer; { x counter for looking at array }
- Temp,L_Data : Byte; { array data }
- BEGIN
- Valid_Name := False ;
- Show_Mouse ;
- More := Get_In_File( P_Name,F_Name ) ;
- Hide_Mouse ;
- Paint_Rect( 0, 0, 640, 200 ); { erase screen }
- Show_Mouse ;
- IF More THEN
- BEGIN
- I := Pos('.',F_Name);
- IF F_Name[ I+1 ] = 'T' THEN
- BEGIN
- IF F_Name[ I+2 ] = 'N' THEN
- BEGIN
- IF F_Name[ I+3 ] = 'Y' THEN
- BEGIN
- Valid_Name := True;
- END;
- END;
- END;
- IF NOT Valid_Name THEN
- BEGIN
- Alert :='';
- A1 := 'The file name you|picked was not|legal. Use the|extender' ;
- A2 := ' .TNY only.' ;
- Alert := concat( '[3][',A1,A2,'][ OOPS! ]' );
- junk := Do_Alert( Alert, 0 ) ;
- END;
- END;
- Hide_Mouse ;
- END; { of Ask_For_Name }
-
-
- PROCEDURE S_Load;
- VAR
- A1, A2, Alert : Str255 ;
- junk, IO_Handle : Integer ;
- I, K : Integer; { temporary variable }
- K_Byte : Byte ;
- Temp : Long_Integer; { one disk file value }
- Name : Path_Chars ;
- BEGIN
- Make_Path( F_Name, Name );
- IO_Handle := F_Open( Name,2 ) ;
- IF IO_Handle >= 0 THEN
- BEGIN
- Temp := F_Read( IO_Handle,32034,Pic_Buf) ;
- END
- ELSE BEGIN
- Alert :='';
- A1 := 'I could not load a|screen by that|name. I will return|' ;
- A2 := 'you to your desktop.' ;
- Alert := concat( '[2][',A1,A2,'][ *NUTS* ]' );
- Junk := Do_Alert( Alert, 0 ) ;
- END;
- Junk := F_Close( IO_Handle ) ;
- END; { of S_Load }
-
- PROCEDURE U_Copy( Count : Integer ) ;
- VAR
- I, J : Integer ;
- BEGIN
- I := 0 ;
- REPEAT
- J := SHL( I,1 ) ;
- Scn_Buf[ Scn_Buf_Ptr ] := Pic_Buf[ Dat_Ptr + J ] ;
- Scn_Buf[ Scn_Buf_Ptr + 1 ] := Pic_Buf[ Dat_Ptr + J + 1 ] ;
- Scn_Buf_Ptr := Scn_Buf_Ptr + 160 ;
- IF Scn_Buf_Ptr > 32000 THEN
- BEGIN
- Scn_Buf_Ptr := Scn_Buf_Ptr - 31992 ;
- IF Scn_Buf_Ptr > 160 THEN Scn_Buf_Ptr := Scn_Buf_Ptr - 158 ;
- END;
- I := I + 1 ;
- UNTIL I = (Count) ;
- END; { of U_Copy }
-
- PROCEDURE Rep_Copy( Count : Integer ) ;
- VAR
- I : Integer ;
- BEGIN
- FOR I := 1 TO Count DO
- BEGIN
- Scn_Buf[ Scn_Buf_Ptr ] := Pic_Buf[ Dat_Ptr ] ;
- Scn_Buf[ Scn_Buf_Ptr + 1 ] := Pic_Buf[ Dat_Ptr + 1 ] ;
- Scn_Buf_Ptr := Scn_Buf_Ptr + 160 ;
- IF Scn_Buf_Ptr > 32000 THEN
- BEGIN
- Scn_Buf_Ptr := Scn_Buf_Ptr - 31992 ;
- IF Scn_Buf_Ptr > 160 THEN Scn_Buf_Ptr := Scn_Buf_Ptr - 158 ;
- END;
- END;
- END; { of Rep_Copy }
-
-
- PROCEDURE Un_Tiny ;
- { this procedure works with the globle variable - Pic_Buf - which contains the
- raw tiny fomat file data read from a disk file. this procedure un-compacts
- data in this file and stores in the globle variable - Scn_Buf - which then
- can be move to screen memory with the procedure Rest_Scn. }
- { this procedure also makes calls to U_Copy and Rep_Copy }
- { Pic_Buf a place to read picture file data into }
- { Scn_buf a place to stash the screen }
-
- VAR
- Junk : Integer ; { for trow away data return by function call }
- I, J, K : Integer ; { loop and temp color data }
- Ctl_Cnt : Integer; { # of control data bytes }
- Dat_Cnt : Integer; { # of pixil data bytes }
- Ctl_Ptr : Integer ; { position of next control data }
- Ctl_End : Integer ; { end position of control data }
- Dat_End : Integer ; { end position of pixil data }
- Temp_Rez : Byte ; { read first data value into this variable }
- Temp_Ptr : Integer ; { pionter into Pic_Buf }
- Rep_Cnt : Integer ; { counter for repeat of pixil data }
- U_Cnt : Integer ; { counter for Unique pixil data }
- BEGIN
- Scn_Buf_Ptr := 1 ;
- Temp_Rez := Pic_Buf[ 1 ] ;
- { calculate picture file resolution and and if rotation data bytes }
- IF Temp_Rez > 2 THEN Pic_Rez := Temp_Rez - 3 ELSE Pic_Rez := Temp_Rez ;
- If ( Pic_Rez = 0 ) OR ( Pic_Rez = 1 ) THEN { low or med resolution }
- BEGIN
- IF Temp_Rez > 2 THEN { find where color data is and copy }
- BEGIN
- FOR I := 0 TO 15 DO
- BEGIN
- K := SHL( Pic_Buf[ (SHL(I,1)+6) ],8 ) ; { get color data }
- Kolor_Reg[ I ] := K + ( Pic_Buf[ (SHL(I,1)+7) ] ) ;
- END;
- END ELSE
- BEGIN
- FOR I := 0 TO 15 DO
- BEGIN
- K := SHL( Pic_Buf[ (SHL(I,1)+2) ],8 ) ; { get color data }
- Kolor_Reg[ I ] := K + ( Pic_Buf[ (SHL(I,1)+3) ] ) ;
- END;
- END;
- Temp_Ptr := 34 ; { piont to ctl_cnt data in Pic_Buf array }
- IF Temp_Rez > 2 THEN Temp_Ptr := 38 ;
- { find number of control bytes }
- Ctl_Cnt := SHL( Pic_Buf[ Temp_Ptr ],8 ) + Pic_Buf[ Temp_Ptr + 1 ] ;
- { find number of pixil data bytes * 2 }
- Dat_Cnt := SHL( Pic_Buf[ Temp_Ptr + 2 ],8 ) + Pic_Buf[ Temp_Ptr + 3 ] ;
- { set control pointer to start of control and pixil data in array }
- Ctl_Ptr := Temp_Ptr + 4 ;
- Dat_Ptr := Ctl_Ptr + Ctl_Cnt ;
- { find end of the 2 data groups, control and pixil }
- Ctl_End := Ctl_Ptr + Ctl_Cnt - 1 ;
- Dat_End := SHL( Dat_Cnt,1 ) + Ctl_End ;
-
- REPEAT
-
- { if control byte is 0 then repeat data times next 2 control bytes }
- IF Pic_Buf[ Ctl_Ptr ] = 0 THEN
- BEGIN
- Temp_Ptr := Ctl_Ptr + 3 ; { find next Ctl_Ptr for next time through }
- { clculate number of repeats }
- Rep_Cnt :=(SHL(Pic_Buf[(Ctl_Ptr+1)],8 ))+( Pic_Buf[(Ctl_Ptr+2)]) ;
- Rep_Copy( Rep_Cnt ) ;
- Dat_Ptr := Dat_Ptr + 2 ;
- END ;
-
- { if control byte is 1<btye<128 then repeat data that many times }
- IF ( Pic_Buf[ Ctl_Ptr ] > 1 ) AND ( Pic_Buf[ Ctl_Ptr ] < 128 ) THEN
- BEGIN
- Temp_Ptr := Ctl_Ptr + 1 ; { find next Ctl_Ptr for next time through }
- Rep_Cnt := Pic_Buf[ Ctl_Ptr ] ;
- Rep_Copy( Rep_Cnt ) ;
- Dat_Ptr := Dat_Ptr + 2 ;
- END;
-
- { If control byte is = 1 then copy consecutive unique data bytes }
- IF Pic_Buf[ Ctl_Ptr ] = 1 THEN
- BEGIN
- Temp_Ptr := Ctl_Ptr + 3 ; { find next Ctl_Ptr for next time through }
- { clculate number of unique bytes }
- U_Cnt :=(SHL(Pic_Buf[(Ctl_Ptr+1)],8))+( Pic_Buf[(Ctl_Ptr+2)]) ;
- U_Copy( U_Cnt ) ;
- Dat_Ptr := Dat_Ptr + U_Cnt * 2 ;
- END;
-
- { if control byte is > 127 copy that many unique data bytes }
- IF ( Pic_Buf[ Ctl_Ptr ] > 127 ) THEN
- BEGIN
- Temp_Ptr := Ctl_Ptr + 1 ; { find next Ctl_Ptr for next time through }
- { clculate number of unique bytes }
- U_Cnt := ( 256 - Pic_Buf[ Ctl_Ptr ] ) ; { make byte positive }
- U_Copy( U_Cnt ) ;
- Dat_Ptr := Dat_Ptr + (SHL(U_Cnt,1)) ;
- END;
- Ctl_Ptr := Temp_Ptr ;
-
- UNTIL ( Ctl_Ptr > Ctl_End ) OR ( Dat_Ptr > Dat_End ) ;
- END;
- END; { of Un_Tiny }
-
- PROCEDURE Event_Loop ;
- VAR
- which,
- dummy,
- key_state, W_key,
- x, y : integer ;
- msg : Message_Buffer ;
- BEGIN
- REPEAT
- { Get a mouse button event. }
- which := Get_Event( E_Timer | E_Button, $0001, 0, 0,
- 0, { time count of zero - quik return }
- false, 0, 0, 0, 0, false, 0, 0, 0, 0, { no rect's }
- msg, W_Key, { what key }
- dummy, dummy, x, y, key_state ) ;
- UNTIL which<34;
- END ; { of Event_Loop }
-
-
- BEGIN
- IF Init_Gem >= 0 THEN
- BEGIN
- Hide_Mouse;
- P_Name := 'A:\*.TNY';
- F_Name := '' ;
- Paint_Color( 3 );
- Text_Color( 0 );
- Starting_Rez := Screen_Rez ; { gets rez that program was run from }
- X_Screen := Logical_Screen; { gets visible/logical screen address }
- Save_Kolors ; { reads color registers }
- Starting_Kolor_Reg := Kolor_Reg ; { back-up of starting colors }
- REPEAT
- Draw_Mode( 1 ) ;
- Paint_Rect( 0, 0, 640, 200 ); { erase screen }
- Draw_Mode( 2 ) ;
- Draw_String( 90,16,
- '** TINYLOOK ** by Steve Pauley with help from Todd Burkey' );
- Ask_For_Name ; { get file nam e to load }
- IF Valid_Name THEN { if it had .TNY as an extender }
- BEGIN
- S_Load; { load raw data in buffer }
- Un_Tiny ; { uncompress data and store in buffer }
- Set_Screen( X_Screen, X_Screen, Pic_Rez ); { change to picture rez }
- Restore_Kolors ; { sets new picture colors }
- Rest_Scn; { move picture buffer to visible screen }
- Event_Loop ; { wait for left mouse button event }
- Set_Screen( X_Screen, X_Screen, Starting_Rez ); { restore rez }
- Kolor_Reg := Starting_Kolor_Reg ;
- Restore_Kolors ; { restore desk top kolors }
- END;
- UNTIL NOT More ; { if cancel was selected stop program }
- Show_Mouse;
- Exit_Gem ;
- END ;
- END.
-